//
//  CTWebMenuCell.m
//  CTWebViewDemo
//
//  Created by ST on 16/9/12.
//  Copyright © 2016年 CT. All rights reserved.
//

#import "CTWebMenuCell.h"
#import "UIColor+ST.h"
#import "CTWebMenuModel.h"
NS_ASSUME_NONNULL_BEGIN

@interface CTWebMenuCell ()
/** 1. */
@property(nonatomic, strong)UIImageView *imageView;
/** 2. */
@property(nonatomic, strong)UILabel *labelText ;
@end

NS_ASSUME_NONNULL_END

@implementation CTWebMenuCell
#pragma mark - --- 1.init 生命周期 ---
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self.contentView addSubview:self.imageView];
        [self.contentView addSubview:self.labelText];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat imageW = 52;
    CGFloat imageH = imageW;
    CGFloat imageX = (self.bounds.size.width - imageW) / 2;
    CGFloat imageY = 10;
    self.imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
    
    CGFloat labelX = 0;
    CGFloat labelY = CGRectGetMaxY(self.imageView.frame);
    CGFloat labelW = self.bounds.size.width;
    CGFloat labelH = HCTWebMenuCell - labelY - 5;
    self.labelText.frame = CGRectMake(labelX, labelY, labelW, labelH);
}
#pragma mark - --- 2.delegate 视图委托 ---

#pragma mark - --- 3.event response 事件相应 ---

#pragma mark - --- 4.private methods 私有方法 ---
- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
}
#pragma mark - --- 5.setters 属性 ---
- (void)setImageName:(NSString *)imageName
{
    _imageName = imageName;
//    self.imageView.image = [UIImage imageNamed:imageName];
    [self.imageView setImage:[UIImage imageNamed:[imageName stringByAppendingString:@"_n"]]];
    [self.imageView setHighlightedImage:[UIImage imageNamed:[imageName stringByAppendingString:@"_p"]]];
}

- (void)setText:(NSString *)text
{
    _text = text;
    self.labelText.text = text;
}


- (void)setModel:(CTWebMenuModel *)model
{
    _model = model;
    [self.imageView setImage:[UIImage imageNamed:[model.imageName stringByAppendingString:@"_n"]]];
    [self.imageView setHighlightedImage:[UIImage imageNamed:[model.imageName stringByAppendingString:@"_p"]]];
    self.labelText.text = model.title;
}
#pragma mark - --- 6.getters 属性 —--
- (UIImageView *)imageView
{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
    }
    return _imageView;
}

- (UILabel *)labelText
{
    if (!_labelText) {
        _labelText = [[UILabel alloc]init];
        _labelText.font = [UIFont systemFontOfSize:15];
        _labelText.textColor = [UIColor colorWithRed:148.0/255 green:148.0/255 blue:148.0/255 alpha:1.0];
        _labelText.textAlignment = NSTextAlignmentCenter;
    }
    return _labelText;
}
@end

